package com.eCommerce.server.svco.impl;

import java.io.Serializable;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;
import org.springframework.transaction.annotation.Transactional;

import com.eCommerce.corecontract.criteria.ComposantCriteria;
import com.eCommerce.corecontract.dto.CategorieDTO;
import com.eCommerce.corecontract.dto.ComposantDTO;
import com.eCommerce.corecontract.exception.EcommerceException;
import com.eCommerce.corecontract.exception.EcommerceSVCOException;
import com.eCommerce.server.corebackend.sisv.IComposantSISV;
import com.eCommerce.server.corebackend.sisv.IUserSISV;
import com.eCommerce.server.corebackend.sisv.SISVFinder;
import com.eCommerce.server.corebackend.util.BackEndConstants;
import com.eCommercecorecontract.svco.IComposantSVCO;
import org.springframework.remoting.jaxrpc.JaxRpcPortProxyFactoryBean;
@Transactional
public class ComposantSVCOImpl extends AbstractCommonSVCO implements IComposantSVCO , Serializable{

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static Logger log =Logger.getLogger(ComposantSVCOImpl.class);
	
	private SISVFinder sisvFinder;
	private IComposantSISV composantSISVImpl;
	public ComposantSVCOImpl(SISVFinder sisvFinder) throws Exception
	{
		this.sisvFinder=sisvFinder;
		composantSISVImpl = (IComposantSISV) sisvFinder.get(BackEndConstants.SISV_COMPOSANT );
	}
	
	public Long ajouterComposant(ComposantDTO composantDTO)
			throws EcommerceException {
		// TODO Auto-generated method stub
		try {
			return composantSISVImpl.ajouterComposant(composantDTO);
		} 
		catch (EcommerceException ex)
		{
			throw ex;
		}
		
		
		catch (Exception e) {
			// TODO Auto-generated catch block
			Object[] arg1 = new Object[1];
			arg1[0]=composantDTO.getLibelle();//.getNom();
			EcommerceSVCOException svcoException = new EcommerceSVCOException(messagesXmlFileName, "ECOMMERCESISVCOMPOSANT-001", arg1, e.getMessage());
			log.error(svcoException.getMessage());
			throw svcoException;
		}
	}

	public List listerComposants() throws EcommerceException {
		// TODO Auto-generated method stub
		try {
			return composantSISVImpl.listerComposant();//ajouterComposant(composantDTO);
		} 
		catch (EcommerceException ex)
		{
			throw ex;
		}
		
		
		catch (Exception e) {
			// TODO Auto-generated catch block
			Object[] arg1 = new Object[1];
			
			EcommerceSVCOException svcoException = new EcommerceSVCOException(messagesXmlFileName, "ECOMMERCESISVCOMPOSANT-004", arg1, e.getMessage());
			log.error(svcoException.getMessage());
			throw svcoException;
		}
	}


	public void modifierComposant(ComposantDTO composantDTO)
			throws EcommerceException {
		// TODO Auto-generated method stub
		try {
			 composantSISVImpl.modifierComposant(composantDTO);
		} 
		catch (EcommerceException ex)
		{
			throw ex;
		}
		
		
		catch (Exception e) {
			// TODO Auto-generated catch block
			Object[] arg1 = new Object[1];
			arg1[0]=composantDTO.getLibelle();
			EcommerceSVCOException svcoException = new EcommerceSVCOException(messagesXmlFileName, "ECOMMERCESISVCOMPOSANT-002", arg1, e.getMessage());
			log.error(svcoException.getMessage());
			throw svcoException;
		}
		
	}


	public List rechercherComposants(ComposantCriteria composantCriteria)
			throws EcommerceException {
		// TODO Auto-generated method stub
		try {
			return composantSISVImpl.rechercherComposant(composantCriteria);
		} 
		catch (EcommerceException ex)
		{
			throw ex;
		}
		
		
		catch (Exception e) {
			// TODO Auto-generated catch block
			Object[] arg1 = new Object[1];
			
			EcommerceSVCOException svcoException = new EcommerceSVCOException(messagesXmlFileName, "ECOMMERCESISVCOMPOSANT-004", arg1, e.getMessage());
			log.error(svcoException.getMessage());
			throw svcoException;
		}
	}


	public void supprimerComposants(Set<ComposantDTO> composantDTO)
			throws EcommerceException {
		// TODO Auto-generated method stub
		try {
			for(ComposantDTO comp:composantDTO)	 composantSISVImpl.supprimerComposant(comp);
		
		} 
		catch (EcommerceException ex)
		{
			throw ex;
		}
		
		
		catch (Exception e) {
			// TODO Auto-generated catch block
			Object[] arg1 = new Object[1];
			
			EcommerceSVCOException svcoException = new EcommerceSVCOException(messagesXmlFileName, "ECOMMERCESISVCOMPOSANT-005", arg1, e.getMessage());
			log.error(svcoException.getMessage());
			throw svcoException;
		}
		
	}


	public ComposantDTO visualiserComposant(ComposantDTO composantDTO)
			throws EcommerceException {
		// TODO Auto-generated method stub
		try {
			return composantSISVImpl.visualiserComposant(composantDTO);
			
		} 
		catch (EcommerceException ex)
		{
			throw ex;
		}
		
		
		catch (Exception e) {
			// TODO Auto-generated catch block
			Object[] arg1 = new Object[1];
			
			EcommerceSVCOException svcoException = new EcommerceSVCOException(messagesXmlFileName, "ECOMMERCESISVCOMPOSANT-003", arg1, e.getMessage());
			log.error(svcoException.getMessage());
			throw svcoException;
		}
	}

	public List rechercherComposantParCategorie(
			CategorieDTO categorieDTO) throws EcommerceException {
		// TODO Auto-generated method stub
		try {
			
			return composantSISVImpl.rechercherComposantParCategorie(categorieDTO);
			//return listOfCat;//.listerComposant();//ajouterComposant(composantDTO);
		} 
		catch (EcommerceException ex)
		{
			throw ex;
		}
		
		
		catch (Exception e) {
			// TODO Auto-generated catch block
			Object[] arg1 = new Object[1];
			
			EcommerceSVCOException svcoException = new EcommerceSVCOException(messagesXmlFileName, "ECOMMERCESISVCOMPOSANT-004", arg1, e.getMessage());
			log.error(svcoException.getMessage());
			throw svcoException;
		}
	}

}
